package com.eraasoftware.npa.server;

import java.nio.channels.SocketChannel;

public class ServiceListenerPoolFactory {
	static ServiceListener masterService = null;

	// static ServiceListenerPool instance = new
	// ApacheCommonJvmtraServicePoolImpl();
	static ServiceListenerPool instance = new ServiceListenerBlockingQueueImpl();
	static ServiceFactorySetting settings = new ServiceFactorySetting();

	private ServiceListenerPoolFactory() {

		ServiceListener.setPing(settings.getPingBytes());

	}

	public static ServiceFactorySetting getSettings() {
		return settings;
	}

	protected static synchronized ServiceListener newJvmtraService(SocketChannel clientChannel)
			throws IllegalStateException, UnsupportedOperationException, Exception {

		ServiceListener serviceListener = new ServiceListener(clientChannel);
		if (masterService == null) {
			masterService = serviceListener;
			masterService.master(true);

		} else {
			instance.addNewService(serviceListener);

		}

		return serviceListener;

	}

	static protected ServiceListenerPool instance() {
		return instance;
	}

}
